class TaskManager {
public:
    map<int, pair<int, int>> TaskInfo; //优先级 userId
    priority_queue<pair<int, int>> heap; //任务优先级 taskId
    TaskManager(vector<vector<int>>& tasks) {
        for(auto &task:tasks)
        {
            int userid=task[0], taskid=task[1], priority=task[2];
            TaskInfo[taskid]={priority, userid};
            heap.push({priority, taskid});
        }
    }
    
    void add(int userId, int taskId, int priority) {
        TaskInfo[taskId]={priority, userId};
        heap.push({priority, taskId});
    }
    
    void edit(int taskId, int newPriority) {
        if(TaskInfo.find(taskId)!=TaskInfo.end())
        {
            TaskInfo[taskId].first=newPriority;
            heap.push({TaskInfo[taskId].first, taskId});
        }
    }
    
    void rmv(int taskId) {
        TaskInfo.erase(taskId);
    }
    
    int execTop() { //任务优先级 taskId
        while(!heap.empty())
        {
            auto [priority, taskId]=heap.top(); heap.pop();
            //1.没有删除 && 优先级没有修改过
            if(TaskInfo.find(taskId)!=TaskInfo.end() && TaskInfo[taskId].first==priority) 
            {
                int userId=TaskInfo[taskId].second;
                TaskInfo.erase(taskId);
                return userId;
            }
        }
        return -1;
    }
};

/**
 * Your TaskManager object will be instantiated and called as such:
 * TaskManager* obj = new TaskManager(tasks);
 * obj->add(userId,taskId,priority);
 * obj->edit(taskId,newPriority);
 * obj->rmv(taskId);
 * int param_4 = obj->execTop();
 */